var i = 1;
var totalPage = "";
$(function(){
	var token=localStorage.getItem("token");
	gridObj = $.fn.bsgrid.init('g_tabYeh', {
		ajaxType : 'post',
		url :  server_url+'/rest/orderManage/orderList.do?ran=' + Math.random() + '&token=' + token,
		autoLoad : true,
		pageSizeSelect : true,
		stripeRows : true,
		pageSize : 10,
		displayBlankRows : false,
		isProcessLockScreen : true,
		rowSelectedColor : false,
		showPageToolbar:true,
		rowHoverColor:true
	});	
});
function operate(record, rowIndex, colIndex, options) {
	//console.log(record.lstOrderDetail[0].supplyVo.supplyID);
	if(record.shipStatusName=='待发货' && record.lstOrderDetail[0].supplyVo.supplyID == 0){
		return '<a href="javascript:viewOrder(\'' + gridObj.getRecordIndexValue(record.lstOrderDetail[0], 'orderID') + '\');">订单详情</a>'+
	    '<a href="javascript:sendProduct(\'' + gridObj.getRecordIndexValue(record.lstOrderDetail[0], 'orderID') + '\');">确认发货</a>'
	}else{
		return '<a href="javascript:viewOrder(\'' + gridObj.getRecordIndexValue(record.lstOrderDetail[0], 'orderID') + '\');">订单详情</a>';
	}
};
function productName(record, rowIndex, colIndex, options){
	return record.lstOrderDetail[0].productName;
	
};
function supplyName(record, rowIndex, colIndex, options){
	var supply = record.lstOrderDetail[0].supplyVo;
	if(supply != null || supply != ''){
		return supply.supplyName;
	}else{
		return "";
	}
	
};
function supplyArea(record, rowIndex, colIndex, options){
	var supplyArea = record.lstOrderDetail[0].supplyVo;
	if(supplyArea != null || supplyArea != ''){
		return supplyArea.provinceName+','+supplyArea.cityName+','+supplyArea.countyName;
	}else{
		return "";
	}
};
function buyerName(record, rowIndex, colIndex, options){
	//console.log(record.buyer);
	var buyerName = record.buyer;
	if(buyerName != null || buyerName != ''){
		return record.buyer.buyerName;
	}else{
		return "";
	}
};
function buyerArea(record, rowIndex, colIndex, options){
	var buyerArea = record.buyer;
	if(buyerArea != null || buyerArea != ''){
		return buyerArea.provinceName+','+buyerArea.cityName+','+buyerArea.countyName;
	}else{
		return "";
	}
	
}
// 数据表格参数查询
function doSearch() {
	var searchParames = $('#myform').serialize();
	gridObj.search(searchParames);
}


function viewOrder(id){
	var url='orderManage/viewOrder.do?id='+id;
	tl_config.loadToWorkArea(url);
}
//后台发货
function shipment(){
	var realCarrier = jQuery("#realCarrier").val();
	var carrierMobile = jQuery("#carrierMobile").val();
	var carrierCarNo = jQuery("#carrierCarNo").val();
	var orderid = $("#orderIdId").val();$("#orderIdId").val('');
	//var shipBillCode = jQuery("#shipBillCode").val();
	
	/*if(empty(shipBillCode)){
		alert("请填写运单号");
		return;
	}*/
	if(empty(realCarrier)){
		alert("请填写送货员姓名");
		return;
	}else{
		if(empty(carrierMobile)){
			alert("请填写送货员手机号");
			return;
		}else{
			if(!isPhone(carrierMobile)){
				alert("请输入有效的手机号.");
				return;
			}else{
				if(empty(carrierCarNo)){
					alert("请填写送货员车牌号");
					return;
				}
			}
		}
	}
	$('.wrap').css('display','none');
	jQuery.ajax({
		url:server_url+"rest/orderManage/shipment.do",
		data:{userid:userid,orderid:orderid,realCarrier:realCarrier,carrierMobile:carrierMobile,
			carrierCarNo:carrierCarNo},
		type:"post",
		success:function(data){
			alert("发货成功");
			var url="orderManage/list.do?ran="+Math.random();
			tl_config.loadToWorkArea(url);
		}
	});
}
function clearDialogMsg(){
	jQuery("#realCarrier").val('');
	jQuery("#carrierMobile").val('');
	jQuery("#carrierCarNo").val('');
}
function sendProduct(orderId){
	clearDialogMsg();
	jQuery("#orderIdId").val(orderId);
	$('.wrap').css('display','block');
}
function isPhone(userNumb){//验证手机号码
	var reg = /^[1][34578][0-9]{9}$/;
	return reg.test(userNumb);
};
function closeDialog (){
	clearDialogMsg();
	$('.wrap').css('display','none');
}